package com.ps.controller.user;


import com.ps.constant.StatusConstant;
import com.ps.entity.Setmeal;
import com.ps.result.Result;
import com.ps.service.SetmealService;
import com.ps.vo.MedicineItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-药品组合浏览接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/list")
    @Cacheable(value = "setmealCache", key = "#categoryId")
    @ApiOperation("根据分类id查询药品组合")
    public Result<List<Setmeal>> list(Long categoryId) {
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);

        List<Setmeal> list = setmealService.list(setmeal);
        return Result.success(list);
    }


    @GetMapping("/medicine/{id}")
    @ApiOperation("根据药品组合id查询包含的药品列表")
    public Result<List<MedicineItemVO>> medicineList(@PathVariable("id") Long id) {
        List<MedicineItemVO> list = setmealService.getMedicineItemById(id);
        return Result.success(list);
    }
}
